/**
 * Created by LangK on 2016/12/20.
 */
var path = require('path');
var http = require('http');
var express = require('express');
var proxy = require('express-http-proxy');
//使用proxyTable
var proxyMiddleware = require('http-proxy-middleware')

var app = express()

var serverIP = 'http://192.168.1.168:8181'

var proxyTable = {
  '/admin/system': {
    target: 'http://47.93.162.139:8181',
    changeOrigin: true,
  },
  '/admin/double': {
    target: 'http://10.30.49.190:10000',
    changeOrigin: true,
  },
  '/adsys/advertiser': {
    target: 'http://10.30.49.190:8484',
    changeOrigin: true,
  },
  '/adsys/advertisement': {
    target: 'http://10.30.49.190:8484',
    changeOrigin: true,
  },
  '/admin/statistics': {
    target: 'http://47.93.162.139:8282',
    changeOrigin: true,
  },
  '/admin/user': {
    target: 'http://47.93.162.139:8282',
    changeOrigin: true,
  },
  '/V1.0.0/api/file': {
    target: 'http://47.93.117.111:20040',
    changeOrigin: true,
  },
  '/api/user': {
    target: 'http://10.30.49.190:8282',
    changeOrigin: true,
  },
  '/admin/complaint': {
    target: 'http://10.30.49.190:8282',
    changeOrigin: true,
  },
  '/merchantRemote/V1.0.0': {
    target: 'http://10.30.137.35:8080',
    changeOrigin: true,
  },
  '/admin/log': {
    target: 'http://10.30.49.190:13131',
    changeOrigin: true,
  }
}

// 将 proxyTable 中的请求 配置挂载到启动的express服务上
Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context]
  if (typeof options === 'string') {
    options = {
      target: options
    }
  }
  app.use(proxyMiddleware(context, options))
})


app.use(express.static(path.join(__dirname, '/dist/')));


var server = http.createServer(app);


app.listen(8080, function () {
  console.log('运行成功')
});
